Sound Tester

Charlie Veniot10th August 2022 at 7:39pm
' modified version of QB64PE SOUND Example 1 (https://qb64phoenix.com/qb64wiki/index.php/SOUND)
' changes by Charlie Veniot to test BASIC Anywhere Machine's:
'                 - touch device awareness
'                 - popup boxes (confirm and prompt)
'                 - sound waveforms 

bUseTouch = 0
if _touchdevice then bUseTouch = _confirm("It looks like you have a touchscreen device. \n\n Press OKAY to use this program in TOUCHSCREEN MODE. \n\n Press CANCEL if you have and want to use your PHYSICAL KEYBOARD." )

notes$ = "C C#D D#E F F#G G#A A#B "
msg$ = "Select an octave (1 - 7) to play (8 quits):"
dim wave(1-4) as string :wave(1) = "sine" : wave(2) = "square" : wave(3) = "sawtooth" : wave(4) = "triangle"

DO
  CLS
  IF bUseTouch THEN
    octave% = VAL( _prompt(msg$, "") )
  ELSE
    COLOR 9:LOCATE 5, 20: PRINT msg$
    DO: octa$ = INKEY$
        octave% = VAL(octa$)
    LOOP UNTIL (octave% > 0) AND (octave% < 9) 
  END IF
  IF octave% > 0 AND octave% < 8 THEN
  for w = 1 to 4
    _sndwave wave(w)
    LOCATE 15, 6: PRINT SPACE$(70)
    LOCATE 16, 6: PRINT SPACE$(70)
    COLOR 14: LOCATE 14,6: PRINT "Waveform: "; wave(w) : LOCATE 15, 6: PRINT "Octave"; octave%; ":";
    RESTORE Octaves
    FOR i = 1 TO 12
      READ note!
      snd% = CINT(note! * (2 ^ (octave% - 1)))  'calculate note frequency
      COLOR 14: PRINT STR$(snd%);
      c0l = POS(0)
      COLOR 11: LOCATE 16, c0l - 2: PRINT MID$(notes$, 1 + (2 * (i - 1)), 2)
      LOCATE 15, c0l
      IF snd% > 36 THEN SOUND snd%, 12 'error if sound value is < 36
      _DELAY .025
    NEXT i
  next w
  END IF
LOOP UNTIL octave% > 7 
END

Octaves:
DATA 32.7,34.65,36.71,38.9,41.2,43.65,46.25,49,51.91,55,58.27,61.74